<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<?php
    include_once('db.php');

?>


<html >
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Saade: Captura de facturas de clientes</title>
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <link rel="stylesheet" type="text/css" href="css/form.css" />  
        <link rel="stylesheet" href="css/example.css" TYPE="text/css" MEDIA="screen">
        <script type="text/javascript" src="js/bsn.AutoSuggest_c_2.0.js"></script>
        <script src="js/jquery-1.2.6.min.js" type="text/javascript"></script>
        <script type="text/javascript" src="js/tabber.js"></script>
        <script type="text/javascript">

            /* Optional: Temporarily hide the "tabber" class so it does not "flash"
            on the page as plain HTML. After tabber runs, the class is changed
            to "tabberlive" and it will appear. */

            document.write('<style type="text/css">.tabber{display:none;}<\/style>');
        </script>
        <script>
            function cerrar()
            {
                parent.$.fancybox.close();
            }
        </script>
        <script type="text/javascript" src="js/jquery.tools.min.js"></script>

    </head>
    <body style="margin: 0px; padding: 0px;" >


        <?php

            /*     
            echo "<PRE>";
            print_r($_POST);
            echo "</PRE>";
            exit;
            */

            $result2 = mysql_query("SELECT * from corte order by id_corte desc limit 1");
                while ($row2 = mysql_fetch_array($result2)) {
                    $corte =  $row2['id_corte'];
                }

            $empresa = $_POST['empresa'];    
            $cantidad_pago = $_POST['cantidad_pago']; 
            
            $sql = "insert into pago values('',$corte,now(),$empresa, $cantidad_pago) ";   
            //insertamos en la tabla de quincenas
            mysql_query($sql, $link);
            // comprobar inserción
            $my_error = mysql_error($link);
            if (!empty($my_error)) {
                echo "Ha habido un error al insertar los valores de tabla pagos. $my_error";
            } else{

                $result2 = mysql_query("SELECT id_pago from pago order by id_pago desc limit 1");
                while ($row2 = mysql_fetch_array($result2)) {
                    $consecutivo =  $row2['id_pago'];
                }


                $link_imprime = "\"http://localhost/comercializadora/imprime_pago_empresa.php?p=$consecutivo\""; 
            ?>
            <script type="text/javascript">
                window.open (<?php echo $link_imprime  ?>,"Imprime pago");
            </script>

            <?php   }  

        ?>
        <div class="header_fancy">
            <div class="cerrar_fancy" onclick="cerrar();"></div> 
            <p style="margin-left: 23px; padding-top: 20px; margin-top:0px">REGISTRAR PAGO DE EMPRESA</p>

        </div>
        <br><br>
        <table id="forma" align="center">
            <tr>
                <td> 
                    <span class="input_fancy2">EL PAGO DE LA EMPRESA HA SIDO REGISTRADO.</span>
                </td>
            </tr>
        </table>
        <script>
            $("#ingrediente").validator();
        </script>
    </body>
</html>
